<?php

$db_hostname = 'localhost';
$db_name = 'eve';
$db_username = 'root';
$db_password = '';

function outputQuery($sql, $params = array())
{
	global $db_hostname, $db_name, $db_username, $db_password;
	
	$dbh = new PDO('mysql:host=' . $db_hostname . ';dbname=' . $db_name, $db_username, $db_password);
	$result = $dbh->prepare($sql);
	$result->execute($params);

	$data = array();
	
	while( $row = $result->fetch(PDO::FETCH_ASSOC) )
	{
		$record = new StdClass();
		
		foreach( $row as $field => $value )
		{
			$record->$field = $value;
		}

		$data[] = $record;
	}
	
	$output = json_encode($data);
	header('Content-Type: application/json');
	header('Content-Length: ' . strlen($output));
	print $output;	
}
